/*! \file Handle.inl
 *	\brief 
 *
 *	created:	2010/11/23
 *	created:	23:11:2010   10:15
 *	filename: 	C:\src\tactics-engine\libs\utils\Handle.inl
 *	file path:	C:\src\tactics-engine\libs\utils
 *	file base:	Handle
 *	file ext:	inl
 *	author:		Vitalii Trubchaninov
 *				vitalii.trubchaninov@ubisoft.com
 */

namespace tt{
namespace utils{

inline
Handle::Handle(HANDLE handle)
: m_handle(handle)
{

}

inline
Handle::~Handle()
{
	if(valid())
	{
		CloseHandle(m_handle);
		m_handle = INVALID_HANDLE_VALUE;
	}
}

inline
bool Handle::valid() const
{
	return (m_handle != NULL) && (m_handle != INVALID_HANDLE_VALUE);
}

inline
void Handle::reset( HANDLE handle )
{
	Handle(handle).swap(*this);
}

inline
void Handle::swap( Handle& other )
{
	std::swap(m_handle, other.m_handle);
}

inline
Handle::operator HANDLE() const
{
	return m_handle;
}

inline
Handle::operator bool() const
{
	return valid();
}

} //namespace utils
} //namespace tt
